package Offer;

/**
 * 替换空格
 * @author 是阿秋啊
 * @date 2022/03/31 16:11
 **/
public class Num05 {
    public String replaceSpace(String s) {
        if (s.length() == 0) {
            return "";
        }
        StringBuilder sb = new StringBuilder();
        int len =s.length();
        int i = 0;
        while (i < len) {
            while (i < len && s.charAt(i) != ' ') {
                sb.append(s.charAt(i));
                i++;
            }
            if (i >= len) {
                break;
            }
            sb.append("%20");
            i++;
        }
        return sb.toString();
    }
}
